package com.game.base.utils.device;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.util.DisplayMetrics;

import com.game.base.app.App;
import com.game.base.utils.toast.ToastUtil;

import static android.content.Context.CLIPBOARD_SERVICE;

public class DeviceUtil {
    private static Context getContext() {
        return App.sInstance;
    }

    /**
     * 获取屏幕宽高
     */
    public static int getWidth() {
        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        return displayMetrics.widthPixels;
    }

    /**
     * 获取屏幕宽高
     */
    public static int getHeight() {
        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        return displayMetrics.heightPixels;
    }

    /**
     * 复制文本到系统剪切板
     */
    public static void copyText(Context context, String text) {
        ClipboardManager myClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        ClipData myClip = ClipData.newPlainText("text", text);
        myClipboard.setPrimaryClip(myClip);
        ToastUtil.showShort("复制完成");
    }
}